﻿


using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;//Please add references
namespace Gift.DAL
{
	/// <summary>
	/// 数据访问类:DALMember
	/// </summary>
	public partial class DALMember
	{
		public DALMember()
		{}
		#region  Method
		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int memberid)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from tbMember");
			strSql.Append(" where memberid=@memberid");
			SqlParameter[] parameters = {
					new SqlParameter("@memberid", SqlDbType.Int,4)
			};
			parameters[0].Value = memberid;

			return DbHelperSQL.Exists(strSql.ToString(),parameters);
		}



        public bool ExistsByLoginName(string sMemberlogin)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from tbMember");
            strSql.Append(" where memberlogin=@memberlogin");
            SqlParameter[] parameters = {
					new SqlParameter("@memberlogin", SqlDbType.NVarChar,150)
			};
            parameters[0].Value = sMemberlogin;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }



        public bool ExistsByEmail(string sExistsByEmail)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from tbMember");
            strSql.Append(" where email=@email");
            SqlParameter[] parameters = {
					new SqlParameter("@email", SqlDbType.NVarChar,150)
			};
            parameters[0].Value = sExistsByEmail;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }




		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int Add(Gift.Model.tbMember model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into tbMember(");
			strSql.Append("memberlogin,memberpwd,membername,sex,birthday,tel1,tel2,phone,email,msn,qq,address,updatetime,logintime,lastime,lastip,flag,state,question,answer,province,city,xinprice,post,rankid,price1,price2,score1,score2,score3,cardcode,videcode,money,registerTime)");
			strSql.Append(" values (");
			strSql.Append("@memberlogin,@memberpwd,@membername,@sex,@birthday,@tel1,@tel2,@phone,@email,@msn,@qq,@address,@updatetime,@logintime,@lastime,@lastip,@flag,@state,@question,@answer,@province,@city,@xinprice,@post,@rankid,@price1,@price2,@score1,@score2,@score3,@cardcode,@videcode,@money,@registerTime)");
			strSql.Append(";select @@IDENTITY");
			SqlParameter[] parameters = {
					new SqlParameter("@memberlogin", SqlDbType.NVarChar,150),
					new SqlParameter("@memberpwd", SqlDbType.NVarChar,150),
					new SqlParameter("@membername", SqlDbType.NVarChar,150),
					new SqlParameter("@sex", SqlDbType.NVarChar,50),
					new SqlParameter("@birthday", SqlDbType.DateTime),
					new SqlParameter("@tel1", SqlDbType.NVarChar,50),
					new SqlParameter("@tel2", SqlDbType.NVarChar,50),
					new SqlParameter("@phone", SqlDbType.NVarChar,50),
					new SqlParameter("@email", SqlDbType.NVarChar,50),
					new SqlParameter("@msn", SqlDbType.NVarChar,50),
					new SqlParameter("@qq", SqlDbType.NVarChar,50),
					new SqlParameter("@address", SqlDbType.NVarChar,50),
					new SqlParameter("@updatetime", SqlDbType.DateTime),
					new SqlParameter("@logintime", SqlDbType.Int,4),
					new SqlParameter("@lastime", SqlDbType.DateTime),
					new SqlParameter("@lastip", SqlDbType.NVarChar,50),
					new SqlParameter("@flag", SqlDbType.Int,4),
					new SqlParameter("@state", SqlDbType.Bit,1),
					new SqlParameter("@question", SqlDbType.NVarChar,150),
					new SqlParameter("@answer", SqlDbType.NVarChar,150),
					new SqlParameter("@province", SqlDbType.NVarChar,50),
					new SqlParameter("@city", SqlDbType.NVarChar,50),
					new SqlParameter("@xinprice", SqlDbType.NVarChar,50),
					new SqlParameter("@post", SqlDbType.NVarChar,50),
					new SqlParameter("@rankid", SqlDbType.Int,4),
					new SqlParameter("@price1", SqlDbType.Real,4),
					new SqlParameter("@price2", SqlDbType.Real,4),
					new SqlParameter("@score1", SqlDbType.Int,4),
					new SqlParameter("@score2", SqlDbType.Int,4),
					new SqlParameter("@score3", SqlDbType.Int,4),
					new SqlParameter("@cardcode", SqlDbType.Int,4),
					new SqlParameter("@videcode", SqlDbType.NVarChar,50),
					new SqlParameter("@money", SqlDbType.Real,4),
					new SqlParameter("@registerTime", SqlDbType.DateTime)};
			parameters[0].Value = model.memberlogin;
			parameters[1].Value = model.memberpwd;
			parameters[2].Value = model.membername;
			parameters[3].Value = model.sex;
			parameters[4].Value = model.birthday;
			parameters[5].Value = model.tel1;
			parameters[6].Value = model.tel2;
			parameters[7].Value = model.phone;
			parameters[8].Value = model.email;
			parameters[9].Value = model.msn;
			parameters[10].Value = model.qq;
			parameters[11].Value = model.address;
			parameters[12].Value = model.updatetime;
			parameters[13].Value = model.logintime;
			parameters[14].Value = model.lastime;
			parameters[15].Value = model.lastip;
			parameters[16].Value = model.flag;
			parameters[17].Value = model.state;
			parameters[18].Value = model.question;
			parameters[19].Value = model.answer;
			parameters[20].Value = model.province;
			parameters[21].Value = model.city;
			parameters[22].Value = model.xinprice;
			parameters[23].Value = model.post;
			parameters[24].Value = model.rankid;
			parameters[25].Value = model.price1;
			parameters[26].Value = model.price2;
			parameters[27].Value = model.score1;
			parameters[28].Value = model.score2;
			parameters[29].Value = model.score3;
			parameters[30].Value = model.cardcode;
			parameters[31].Value = model.videcode;
			parameters[32].Value = model.money;
			parameters[33].Value = model.registerTime;

			object obj = DbHelperSQL.GetSingle(strSql.ToString(),parameters);
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}



		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(Gift.Model.tbMember model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update tbMember set ");
			strSql.Append("memberlogin=@memberlogin,");
			strSql.Append("memberpwd=@memberpwd,");
			strSql.Append("membername=@membername,");
			strSql.Append("sex=@sex,");
			strSql.Append("birthday=@birthday,");
			strSql.Append("tel1=@tel1,");
			strSql.Append("tel2=@tel2,");
			strSql.Append("phone=@phone,");
			strSql.Append("email=@email,");
			strSql.Append("msn=@msn,");
			strSql.Append("qq=@qq,");
			strSql.Append("address=@address,");
			strSql.Append("updatetime=@updatetime,");
			strSql.Append("logintime=@logintime,");
			strSql.Append("lastime=@lastime,");
			strSql.Append("lastip=@lastip,");
			strSql.Append("flag=@flag,");
			strSql.Append("state=@state,");
			strSql.Append("question=@question,");
			strSql.Append("answer=@answer,");
			strSql.Append("province=@province,");
			strSql.Append("city=@city,");
			strSql.Append("xinprice=@xinprice,");
			strSql.Append("post=@post,");
			strSql.Append("rankid=@rankid,");
			strSql.Append("price1=@price1,");
			strSql.Append("price2=@price2,");
			strSql.Append("score1=@score1,");
			strSql.Append("score2=@score2,");
			strSql.Append("score3=@score3,");
			strSql.Append("cardcode=@cardcode,");
			strSql.Append("videcode=@videcode,");
			strSql.Append("money=@money,");
			strSql.Append("registerTime=@registerTime,");
            strSql.Append("sendCount=@sendCount");
			strSql.Append(" where memberid=@memberid");
			SqlParameter[] parameters = {
					new SqlParameter("@memberlogin", SqlDbType.NVarChar,150),
					new SqlParameter("@memberpwd", SqlDbType.NVarChar,150),
					new SqlParameter("@membername", SqlDbType.NVarChar,150),
					new SqlParameter("@sex", SqlDbType.NVarChar,50),
					new SqlParameter("@birthday", SqlDbType.DateTime),
					new SqlParameter("@tel1", SqlDbType.NVarChar,50),
					new SqlParameter("@tel2", SqlDbType.NVarChar,50),
					new SqlParameter("@phone", SqlDbType.NVarChar,50),
					new SqlParameter("@email", SqlDbType.NVarChar,50),
					new SqlParameter("@msn", SqlDbType.NVarChar,50),
					new SqlParameter("@qq", SqlDbType.NVarChar,50),
					new SqlParameter("@address", SqlDbType.NVarChar,50),
					new SqlParameter("@updatetime", SqlDbType.DateTime),
					new SqlParameter("@logintime", SqlDbType.Int,4),
					new SqlParameter("@lastime", SqlDbType.DateTime),
					new SqlParameter("@lastip", SqlDbType.NVarChar,50),
					new SqlParameter("@flag", SqlDbType.Int,4),
					new SqlParameter("@state", SqlDbType.Bit,1),
					new SqlParameter("@question", SqlDbType.NVarChar,150),
					new SqlParameter("@answer", SqlDbType.NVarChar,150),
					new SqlParameter("@province", SqlDbType.NVarChar,50),
					new SqlParameter("@city", SqlDbType.NVarChar,50),
					new SqlParameter("@xinprice", SqlDbType.NVarChar,50),
					new SqlParameter("@post", SqlDbType.NVarChar,50),
					new SqlParameter("@rankid", SqlDbType.Int,4),
					new SqlParameter("@price1", SqlDbType.Real,4),
					new SqlParameter("@price2", SqlDbType.Real,4),
					new SqlParameter("@score1", SqlDbType.Int,4),
					new SqlParameter("@score2", SqlDbType.Int,4),
					new SqlParameter("@score3", SqlDbType.Int,4),
					new SqlParameter("@cardcode", SqlDbType.Int,4),
					new SqlParameter("@videcode", SqlDbType.NVarChar,50),
					new SqlParameter("@money", SqlDbType.Real,4),
					new SqlParameter("@registerTime", SqlDbType.DateTime),
					new SqlParameter("@memberid", SqlDbType.Int,4),
                    new SqlParameter("@sendCount", SqlDbType.Int,4)
                                        };
			parameters[0].Value = model.memberlogin;
			parameters[1].Value = model.memberpwd;
			parameters[2].Value = model.membername;
			parameters[3].Value = model.sex;
			parameters[4].Value = model.birthday;
			parameters[5].Value = model.tel1;
			parameters[6].Value = model.tel2;
			parameters[7].Value = model.phone;
			parameters[8].Value = model.email;
			parameters[9].Value = model.msn;
			parameters[10].Value = model.qq;
			parameters[11].Value = model.address;
			parameters[12].Value = model.updatetime;
			parameters[13].Value = model.logintime;
			parameters[14].Value = model.lastime;
			parameters[15].Value = model.lastip;
			parameters[16].Value = model.flag;
			parameters[17].Value = model.state;
			parameters[18].Value = model.question;
			parameters[19].Value = model.answer;
			parameters[20].Value = model.province;
			parameters[21].Value = model.city;
			parameters[22].Value = model.xinprice;
			parameters[23].Value = model.post;
			parameters[24].Value = model.rankid;
			parameters[25].Value = model.price1;
			parameters[26].Value = model.price2;
			parameters[27].Value = model.score1;
			parameters[28].Value = model.score2;
			parameters[29].Value = model.score3;
			parameters[30].Value = model.cardcode;
			parameters[31].Value = model.videcode;
			parameters[32].Value = model.money;
			parameters[33].Value = model.registerTime;
			parameters[34].Value = model.memberid;
            parameters[35].Value = model.SendCount;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int memberid)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from tbMember ");
			strSql.Append(" where memberid=@memberid");
			SqlParameter[] parameters = {
					new SqlParameter("@memberid", SqlDbType.Int,4)
			};
			parameters[0].Value = memberid;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string memberidlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update from tbMember set flag=2 ");
			strSql.Append(" where memberid in ("+memberidlist + ")  ");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Gift.Model.tbMember GetModel(int memberid)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1 memberid,memberlogin,memberpwd,membername,sex,birthday,tel1,tel2,phone,email,msn,qq,address,updatetime,logintime,lastime,lastip,flag,state,question,answer,province,city,xinprice,post,rankid,price1,price2,score1,score2,score3,cardcode,videcode,money,registerTime from tbMember ");
			strSql.Append(" where memberid=@memberid");
			SqlParameter[] parameters = {
					new SqlParameter("@memberid", SqlDbType.Int,4)
			};
			parameters[0].Value = memberid;

			Gift.Model.tbMember model=new Gift.Model.tbMember();
			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["memberid"]!=null && ds.Tables[0].Rows[0]["memberid"].ToString()!="")
				{
					model.memberid=int.Parse(ds.Tables[0].Rows[0]["memberid"].ToString());
				}
				if(ds.Tables[0].Rows[0]["memberlogin"]!=null && ds.Tables[0].Rows[0]["memberlogin"].ToString()!="")
				{
					model.memberlogin=ds.Tables[0].Rows[0]["memberlogin"].ToString();
				}
				if(ds.Tables[0].Rows[0]["memberpwd"]!=null && ds.Tables[0].Rows[0]["memberpwd"].ToString()!="")
				{
					model.memberpwd=ds.Tables[0].Rows[0]["memberpwd"].ToString();
				}
				if(ds.Tables[0].Rows[0]["membername"]!=null && ds.Tables[0].Rows[0]["membername"].ToString()!="")
				{
					model.membername=ds.Tables[0].Rows[0]["membername"].ToString();
				}
				if(ds.Tables[0].Rows[0]["sex"]!=null && ds.Tables[0].Rows[0]["sex"].ToString()!="")
				{
					model.sex=ds.Tables[0].Rows[0]["sex"].ToString();
				}
				if(ds.Tables[0].Rows[0]["birthday"]!=null && ds.Tables[0].Rows[0]["birthday"].ToString()!="")
				{
					model.birthday=DateTime.Parse(ds.Tables[0].Rows[0]["birthday"].ToString());
				}
				if(ds.Tables[0].Rows[0]["tel1"]!=null && ds.Tables[0].Rows[0]["tel1"].ToString()!="")
				{
					model.tel1=ds.Tables[0].Rows[0]["tel1"].ToString();
				}
				if(ds.Tables[0].Rows[0]["tel2"]!=null && ds.Tables[0].Rows[0]["tel2"].ToString()!="")
				{
					model.tel2=ds.Tables[0].Rows[0]["tel2"].ToString();
				}
				if(ds.Tables[0].Rows[0]["phone"]!=null && ds.Tables[0].Rows[0]["phone"].ToString()!="")
				{
					model.phone=ds.Tables[0].Rows[0]["phone"].ToString();
				}
				if(ds.Tables[0].Rows[0]["email"]!=null && ds.Tables[0].Rows[0]["email"].ToString()!="")
				{
					model.email=ds.Tables[0].Rows[0]["email"].ToString();
				}
				if(ds.Tables[0].Rows[0]["msn"]!=null && ds.Tables[0].Rows[0]["msn"].ToString()!="")
				{
					model.msn=ds.Tables[0].Rows[0]["msn"].ToString();
				}
				if(ds.Tables[0].Rows[0]["qq"]!=null && ds.Tables[0].Rows[0]["qq"].ToString()!="")
				{
					model.qq=ds.Tables[0].Rows[0]["qq"].ToString();
				}
				if(ds.Tables[0].Rows[0]["address"]!=null && ds.Tables[0].Rows[0]["address"].ToString()!="")
				{
					model.address=ds.Tables[0].Rows[0]["address"].ToString();
				}
				if(ds.Tables[0].Rows[0]["updatetime"]!=null && ds.Tables[0].Rows[0]["updatetime"].ToString()!="")
				{
					model.updatetime=DateTime.Parse(ds.Tables[0].Rows[0]["updatetime"].ToString());
				}
				if(ds.Tables[0].Rows[0]["logintime"]!=null && ds.Tables[0].Rows[0]["logintime"].ToString()!="")
				{
					model.logintime=int.Parse(ds.Tables[0].Rows[0]["logintime"].ToString());
				}
				if(ds.Tables[0].Rows[0]["lastime"]!=null && ds.Tables[0].Rows[0]["lastime"].ToString()!="")
				{
					model.lastime=DateTime.Parse(ds.Tables[0].Rows[0]["lastime"].ToString());
				}
				if(ds.Tables[0].Rows[0]["lastip"]!=null && ds.Tables[0].Rows[0]["lastip"].ToString()!="")
				{
					model.lastip=ds.Tables[0].Rows[0]["lastip"].ToString();
				}
				if(ds.Tables[0].Rows[0]["flag"]!=null && ds.Tables[0].Rows[0]["flag"].ToString()!="")
				{
					model.flag=int.Parse(ds.Tables[0].Rows[0]["flag"].ToString());
				}
				if(ds.Tables[0].Rows[0]["state"]!=null && ds.Tables[0].Rows[0]["state"].ToString()!="")
				{
					if((ds.Tables[0].Rows[0]["state"].ToString()=="1")||(ds.Tables[0].Rows[0]["state"].ToString().ToLower()=="true"))
					{
						model.state=true;
					}
					else
					{
						model.state=false;
					}
				}
				if(ds.Tables[0].Rows[0]["question"]!=null && ds.Tables[0].Rows[0]["question"].ToString()!="")
				{
					model.question=ds.Tables[0].Rows[0]["question"].ToString();
				}
				if(ds.Tables[0].Rows[0]["answer"]!=null && ds.Tables[0].Rows[0]["answer"].ToString()!="")
				{
					model.answer=ds.Tables[0].Rows[0]["answer"].ToString();
				}
				if(ds.Tables[0].Rows[0]["province"]!=null && ds.Tables[0].Rows[0]["province"].ToString()!="")
				{
					model.province=ds.Tables[0].Rows[0]["province"].ToString();
				}
				if(ds.Tables[0].Rows[0]["city"]!=null && ds.Tables[0].Rows[0]["city"].ToString()!="")
				{
					model.city=ds.Tables[0].Rows[0]["city"].ToString();
				}
				if(ds.Tables[0].Rows[0]["xinprice"]!=null && ds.Tables[0].Rows[0]["xinprice"].ToString()!="")
				{
					model.xinprice=ds.Tables[0].Rows[0]["xinprice"].ToString();
				}
				if(ds.Tables[0].Rows[0]["post"]!=null && ds.Tables[0].Rows[0]["post"].ToString()!="")
				{
					model.post=ds.Tables[0].Rows[0]["post"].ToString();
				}
				if(ds.Tables[0].Rows[0]["rankid"]!=null && ds.Tables[0].Rows[0]["rankid"].ToString()!="")
				{
					model.rankid=int.Parse(ds.Tables[0].Rows[0]["rankid"].ToString());
				}
				if(ds.Tables[0].Rows[0]["price1"]!=null && ds.Tables[0].Rows[0]["price1"].ToString()!="")
				{
					model.price1=decimal.Parse(ds.Tables[0].Rows[0]["price1"].ToString());
				}
				if(ds.Tables[0].Rows[0]["price2"]!=null && ds.Tables[0].Rows[0]["price2"].ToString()!="")
				{
					model.price2=decimal.Parse(ds.Tables[0].Rows[0]["price2"].ToString());
				}
				if(ds.Tables[0].Rows[0]["score1"]!=null && ds.Tables[0].Rows[0]["score1"].ToString()!="")
				{
					model.score1=int.Parse(ds.Tables[0].Rows[0]["score1"].ToString());
				}
				if(ds.Tables[0].Rows[0]["score2"]!=null && ds.Tables[0].Rows[0]["score2"].ToString()!="")
				{
					model.score2=int.Parse(ds.Tables[0].Rows[0]["score2"].ToString());
				}
				if(ds.Tables[0].Rows[0]["score3"]!=null && ds.Tables[0].Rows[0]["score3"].ToString()!="")
				{
					model.score3=int.Parse(ds.Tables[0].Rows[0]["score3"].ToString());
				}
				if(ds.Tables[0].Rows[0]["cardcode"]!=null && ds.Tables[0].Rows[0]["cardcode"].ToString()!="")
				{
					model.cardcode=int.Parse(ds.Tables[0].Rows[0]["cardcode"].ToString());
				}
				if(ds.Tables[0].Rows[0]["videcode"]!=null && ds.Tables[0].Rows[0]["videcode"].ToString()!="")
				{
					model.videcode=ds.Tables[0].Rows[0]["videcode"].ToString();
				}
				if(ds.Tables[0].Rows[0]["money"]!=null && ds.Tables[0].Rows[0]["money"].ToString()!="")
				{
					model.money=decimal.Parse(ds.Tables[0].Rows[0]["money"].ToString());
				}
				if(ds.Tables[0].Rows[0]["registerTime"]!=null && ds.Tables[0].Rows[0]["registerTime"].ToString()!="")
				{
					model.registerTime=DateTime.Parse(ds.Tables[0].Rows[0]["registerTime"].ToString());
				}
				return model;
			}
			else
			{
				return null;
			}
		}


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Gift.Model.tbMember GetModel(string sMemberLoginOrEmail)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 memberid,memberlogin,memberpwd,membername,sex,birthday,tel1,tel2,phone,email,msn,qq,address,updatetime,logintime,lastime,lastip,flag,state,question,answer,province,city,xinprice,post,rankid,price1,price2,score1,score2,score3,cardcode,videcode,money,registerTime,isnull(sendCount,0) as sendCount from tbMember ");
            strSql.Append(" where memberlogin=@memberLoginOrEmail or email=@memberLoginOrEmail");
            SqlParameter[] parameters = {
					new SqlParameter("@memberLoginOrEmail", SqlDbType.NVarChar,100)
			};
            parameters[0].Value = sMemberLoginOrEmail;

            Gift.Model.tbMember model = new Gift.Model.tbMember();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["memberid"] != null && ds.Tables[0].Rows[0]["memberid"].ToString() != "")
                {
                    model.memberid = int.Parse(ds.Tables[0].Rows[0]["memberid"].ToString());
                }
                if (ds.Tables[0].Rows[0]["memberlogin"] != null && ds.Tables[0].Rows[0]["memberlogin"].ToString() != "")
                {
                    model.memberlogin = ds.Tables[0].Rows[0]["memberlogin"].ToString();
                }
                if (ds.Tables[0].Rows[0]["memberpwd"] != null && ds.Tables[0].Rows[0]["memberpwd"].ToString() != "")
                {
                    model.memberpwd = ds.Tables[0].Rows[0]["memberpwd"].ToString();
                }
                if (ds.Tables[0].Rows[0]["membername"] != null && ds.Tables[0].Rows[0]["membername"].ToString() != "")
                {
                    model.membername = ds.Tables[0].Rows[0]["membername"].ToString();
                }
                if (ds.Tables[0].Rows[0]["sex"] != null && ds.Tables[0].Rows[0]["sex"].ToString() != "")
                {
                    model.sex = ds.Tables[0].Rows[0]["sex"].ToString();
                }
                if (ds.Tables[0].Rows[0]["birthday"] != null && ds.Tables[0].Rows[0]["birthday"].ToString() != "")
                {
                    model.birthday = DateTime.Parse(ds.Tables[0].Rows[0]["birthday"].ToString());
                }
                if (ds.Tables[0].Rows[0]["tel1"] != null && ds.Tables[0].Rows[0]["tel1"].ToString() != "")
                {
                    model.tel1 = ds.Tables[0].Rows[0]["tel1"].ToString();
                }
                if (ds.Tables[0].Rows[0]["tel2"] != null && ds.Tables[0].Rows[0]["tel2"].ToString() != "")
                {
                    model.tel2 = ds.Tables[0].Rows[0]["tel2"].ToString();
                }
                if (ds.Tables[0].Rows[0]["phone"] != null && ds.Tables[0].Rows[0]["phone"].ToString() != "")
                {
                    model.phone = ds.Tables[0].Rows[0]["phone"].ToString();
                }
                if (ds.Tables[0].Rows[0]["email"] != null && ds.Tables[0].Rows[0]["email"].ToString() != "")
                {
                    model.email = ds.Tables[0].Rows[0]["email"].ToString();
                }
                if (ds.Tables[0].Rows[0]["msn"] != null && ds.Tables[0].Rows[0]["msn"].ToString() != "")
                {
                    model.msn = ds.Tables[0].Rows[0]["msn"].ToString();
                }
                if (ds.Tables[0].Rows[0]["qq"] != null && ds.Tables[0].Rows[0]["qq"].ToString() != "")
                {
                    model.qq = ds.Tables[0].Rows[0]["qq"].ToString();
                }
                if (ds.Tables[0].Rows[0]["address"] != null && ds.Tables[0].Rows[0]["address"].ToString() != "")
                {
                    model.address = ds.Tables[0].Rows[0]["address"].ToString();
                }
                if (ds.Tables[0].Rows[0]["updatetime"] != null && ds.Tables[0].Rows[0]["updatetime"].ToString() != "")
                {
                    model.updatetime = DateTime.Parse(ds.Tables[0].Rows[0]["updatetime"].ToString());
                }
                if (ds.Tables[0].Rows[0]["logintime"] != null && ds.Tables[0].Rows[0]["logintime"].ToString() != "")
                {
                    model.logintime = int.Parse(ds.Tables[0].Rows[0]["logintime"].ToString());
                }
                if (ds.Tables[0].Rows[0]["lastime"] != null && ds.Tables[0].Rows[0]["lastime"].ToString() != "")
                {
                    model.lastime = DateTime.Parse(ds.Tables[0].Rows[0]["lastime"].ToString());
                }
                if (ds.Tables[0].Rows[0]["lastip"] != null && ds.Tables[0].Rows[0]["lastip"].ToString() != "")
                {
                    model.lastip = ds.Tables[0].Rows[0]["lastip"].ToString();
                }
                if (ds.Tables[0].Rows[0]["flag"] != null && ds.Tables[0].Rows[0]["flag"].ToString() != "")
                {
                    model.flag = int.Parse(ds.Tables[0].Rows[0]["flag"].ToString());
                }
                if (ds.Tables[0].Rows[0]["state"] != null && ds.Tables[0].Rows[0]["state"].ToString() != "")
                {
                    if ((ds.Tables[0].Rows[0]["state"].ToString() == "1") || (ds.Tables[0].Rows[0]["state"].ToString().ToLower() == "true"))
                    {
                        model.state = true;
                    }
                    else
                    {
                        model.state = false;
                    }
                }
                if (ds.Tables[0].Rows[0]["question"] != null && ds.Tables[0].Rows[0]["question"].ToString() != "")
                {
                    model.question = ds.Tables[0].Rows[0]["question"].ToString();
                }
                if (ds.Tables[0].Rows[0]["answer"] != null && ds.Tables[0].Rows[0]["answer"].ToString() != "")
                {
                    model.answer = ds.Tables[0].Rows[0]["answer"].ToString();
                }
                if (ds.Tables[0].Rows[0]["province"] != null && ds.Tables[0].Rows[0]["province"].ToString() != "")
                {
                    model.province = ds.Tables[0].Rows[0]["province"].ToString();
                }
                if (ds.Tables[0].Rows[0]["city"] != null && ds.Tables[0].Rows[0]["city"].ToString() != "")
                {
                    model.city = ds.Tables[0].Rows[0]["city"].ToString();
                }
                if (ds.Tables[0].Rows[0]["xinprice"] != null && ds.Tables[0].Rows[0]["xinprice"].ToString() != "")
                {
                    model.xinprice = ds.Tables[0].Rows[0]["xinprice"].ToString();
                }
                if (ds.Tables[0].Rows[0]["post"] != null && ds.Tables[0].Rows[0]["post"].ToString() != "")
                {
                    model.post = ds.Tables[0].Rows[0]["post"].ToString();
                }
                if (ds.Tables[0].Rows[0]["rankid"] != null && ds.Tables[0].Rows[0]["rankid"].ToString() != "")
                {
                    model.rankid = int.Parse(ds.Tables[0].Rows[0]["rankid"].ToString());
                }
                if (ds.Tables[0].Rows[0]["price1"] != null && ds.Tables[0].Rows[0]["price1"].ToString() != "")
                {
                    model.price1 = decimal.Parse(ds.Tables[0].Rows[0]["price1"].ToString());
                }
                if (ds.Tables[0].Rows[0]["price2"] != null && ds.Tables[0].Rows[0]["price2"].ToString() != "")
                {
                    model.price2 = decimal.Parse(ds.Tables[0].Rows[0]["price2"].ToString());
                }
                if (ds.Tables[0].Rows[0]["score1"] != null && ds.Tables[0].Rows[0]["score1"].ToString() != "")
                {
                    model.score1 = int.Parse(ds.Tables[0].Rows[0]["score1"].ToString());
                }
                if (ds.Tables[0].Rows[0]["score2"] != null && ds.Tables[0].Rows[0]["score2"].ToString() != "")
                {
                    model.score2 = int.Parse(ds.Tables[0].Rows[0]["score2"].ToString());
                }
                if (ds.Tables[0].Rows[0]["score3"] != null && ds.Tables[0].Rows[0]["score3"].ToString() != "")
                {
                    model.score3 = int.Parse(ds.Tables[0].Rows[0]["score3"].ToString());
                }
                if (ds.Tables[0].Rows[0]["cardcode"] != null && ds.Tables[0].Rows[0]["cardcode"].ToString() != "")
                {
                    model.cardcode = int.Parse(ds.Tables[0].Rows[0]["cardcode"].ToString());
                }
                if (ds.Tables[0].Rows[0]["videcode"] != null && ds.Tables[0].Rows[0]["videcode"].ToString() != "")
                {
                    model.videcode = ds.Tables[0].Rows[0]["videcode"].ToString();
                }
                if (ds.Tables[0].Rows[0]["money"] != null && ds.Tables[0].Rows[0]["money"].ToString() != "")
                {
                    model.money = decimal.Parse(ds.Tables[0].Rows[0]["money"].ToString());
                }
                if (ds.Tables[0].Rows[0]["registerTime"] != null && ds.Tables[0].Rows[0]["registerTime"].ToString() != "")
                {
                    model.registerTime = DateTime.Parse(ds.Tables[0].Rows[0]["registerTime"].ToString());
                }
                model.SendCount = int.Parse(ds.Tables[0].Rows[0]["sendCount"].ToString());
                return model;
            }
            else
            {
                return null;
            }
        }



        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Gift.Model.tbMember GetModel(string sMemberLogin,string sMemberpwd)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 memberid,memberlogin,memberpwd,membername,sex,birthday,tel1,tel2,phone,email,msn,qq,address,updatetime,logintime,lastime,lastip,flag,state,question,answer,province,city,xinprice,post,rankid,price1,price2,score1,score2,score3,cardcode,videcode,money,registerTime from tbMember ");
            strSql.Append(" where memberlogin=@memberlogin and memberpwd= @memberpwd");
            SqlParameter[] parameters = {
					new SqlParameter("@memberlogin", SqlDbType.NVarChar,150),
                    new SqlParameter("@memberpwd", SqlDbType.NVarChar,150)

			};
            parameters[0].Value = sMemberLogin;
            parameters[1].Value = sMemberpwd;

            Gift.Model.tbMember model = new Gift.Model.tbMember();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["memberid"] != null && ds.Tables[0].Rows[0]["memberid"].ToString() != "")
                {
                    model.memberid = int.Parse(ds.Tables[0].Rows[0]["memberid"].ToString());
                }
                if (ds.Tables[0].Rows[0]["memberlogin"] != null && ds.Tables[0].Rows[0]["memberlogin"].ToString() != "")
                {
                    model.memberlogin = ds.Tables[0].Rows[0]["memberlogin"].ToString();
                }
                if (ds.Tables[0].Rows[0]["memberpwd"] != null && ds.Tables[0].Rows[0]["memberpwd"].ToString() != "")
                {
                    model.memberpwd = ds.Tables[0].Rows[0]["memberpwd"].ToString();
                }
                if (ds.Tables[0].Rows[0]["membername"] != null && ds.Tables[0].Rows[0]["membername"].ToString() != "")
                {
                    model.membername = ds.Tables[0].Rows[0]["membername"].ToString();
                }
                if (ds.Tables[0].Rows[0]["sex"] != null && ds.Tables[0].Rows[0]["sex"].ToString() != "")
                {
                    model.sex = ds.Tables[0].Rows[0]["sex"].ToString();
                }
                if (ds.Tables[0].Rows[0]["birthday"] != null && ds.Tables[0].Rows[0]["birthday"].ToString() != "")
                {
                    model.birthday = DateTime.Parse(ds.Tables[0].Rows[0]["birthday"].ToString());
                }
                if (ds.Tables[0].Rows[0]["tel1"] != null && ds.Tables[0].Rows[0]["tel1"].ToString() != "")
                {
                    model.tel1 = ds.Tables[0].Rows[0]["tel1"].ToString();
                }
                if (ds.Tables[0].Rows[0]["tel2"] != null && ds.Tables[0].Rows[0]["tel2"].ToString() != "")
                {
                    model.tel2 = ds.Tables[0].Rows[0]["tel2"].ToString();
                }
                if (ds.Tables[0].Rows[0]["phone"] != null && ds.Tables[0].Rows[0]["phone"].ToString() != "")
                {
                    model.phone = ds.Tables[0].Rows[0]["phone"].ToString();
                }
                if (ds.Tables[0].Rows[0]["email"] != null && ds.Tables[0].Rows[0]["email"].ToString() != "")
                {
                    model.email = ds.Tables[0].Rows[0]["email"].ToString();
                }
                if (ds.Tables[0].Rows[0]["msn"] != null && ds.Tables[0].Rows[0]["msn"].ToString() != "")
                {
                    model.msn = ds.Tables[0].Rows[0]["msn"].ToString();
                }
                if (ds.Tables[0].Rows[0]["qq"] != null && ds.Tables[0].Rows[0]["qq"].ToString() != "")
                {
                    model.qq = ds.Tables[0].Rows[0]["qq"].ToString();
                }
                if (ds.Tables[0].Rows[0]["address"] != null && ds.Tables[0].Rows[0]["address"].ToString() != "")
                {
                    model.address = ds.Tables[0].Rows[0]["address"].ToString();
                }
                if (ds.Tables[0].Rows[0]["updatetime"] != null && ds.Tables[0].Rows[0]["updatetime"].ToString() != "")
                {
                    model.updatetime = DateTime.Parse(ds.Tables[0].Rows[0]["updatetime"].ToString());
                }
                if (ds.Tables[0].Rows[0]["logintime"] != null && ds.Tables[0].Rows[0]["logintime"].ToString() != "")
                {
                    model.logintime = int.Parse(ds.Tables[0].Rows[0]["logintime"].ToString());
                }
                if (ds.Tables[0].Rows[0]["lastime"] != null && ds.Tables[0].Rows[0]["lastime"].ToString() != "")
                {
                    model.lastime = DateTime.Parse(ds.Tables[0].Rows[0]["lastime"].ToString());
                }
                if (ds.Tables[0].Rows[0]["lastip"] != null && ds.Tables[0].Rows[0]["lastip"].ToString() != "")
                {
                    model.lastip = ds.Tables[0].Rows[0]["lastip"].ToString();
                }
                if (ds.Tables[0].Rows[0]["flag"] != null && ds.Tables[0].Rows[0]["flag"].ToString() != "")
                {
                    model.flag = int.Parse(ds.Tables[0].Rows[0]["flag"].ToString());
                }
                if (ds.Tables[0].Rows[0]["state"] != null && ds.Tables[0].Rows[0]["state"].ToString() != "")
                {
                    if ((ds.Tables[0].Rows[0]["state"].ToString() == "1") || (ds.Tables[0].Rows[0]["state"].ToString().ToLower() == "true"))
                    {
                        model.state = true;
                    }
                    else
                    {
                        model.state = false;
                    }
                }
                if (ds.Tables[0].Rows[0]["question"] != null && ds.Tables[0].Rows[0]["question"].ToString() != "")
                {
                    model.question = ds.Tables[0].Rows[0]["question"].ToString();
                }
                if (ds.Tables[0].Rows[0]["answer"] != null && ds.Tables[0].Rows[0]["answer"].ToString() != "")
                {
                    model.answer = ds.Tables[0].Rows[0]["answer"].ToString();
                }
                if (ds.Tables[0].Rows[0]["province"] != null && ds.Tables[0].Rows[0]["province"].ToString() != "")
                {
                    model.province = ds.Tables[0].Rows[0]["province"].ToString();
                }
                if (ds.Tables[0].Rows[0]["city"] != null && ds.Tables[0].Rows[0]["city"].ToString() != "")
                {
                    model.city = ds.Tables[0].Rows[0]["city"].ToString();
                }
                if (ds.Tables[0].Rows[0]["xinprice"] != null && ds.Tables[0].Rows[0]["xinprice"].ToString() != "")
                {
                    model.xinprice = ds.Tables[0].Rows[0]["xinprice"].ToString();
                }
                if (ds.Tables[0].Rows[0]["post"] != null && ds.Tables[0].Rows[0]["post"].ToString() != "")
                {
                    model.post = ds.Tables[0].Rows[0]["post"].ToString();
                }
                if (ds.Tables[0].Rows[0]["rankid"] != null && ds.Tables[0].Rows[0]["rankid"].ToString() != "")
                {
                    model.rankid = int.Parse(ds.Tables[0].Rows[0]["rankid"].ToString());
                }
                if (ds.Tables[0].Rows[0]["price1"] != null && ds.Tables[0].Rows[0]["price1"].ToString() != "")
                {
                    model.price1 = decimal.Parse(ds.Tables[0].Rows[0]["price1"].ToString());
                }
                if (ds.Tables[0].Rows[0]["price2"] != null && ds.Tables[0].Rows[0]["price2"].ToString() != "")
                {
                    model.price2 = decimal.Parse(ds.Tables[0].Rows[0]["price2"].ToString());
                }
                if (ds.Tables[0].Rows[0]["score1"] != null && ds.Tables[0].Rows[0]["score1"].ToString() != "")
                {
                    model.score1 = int.Parse(ds.Tables[0].Rows[0]["score1"].ToString());
                }
                if (ds.Tables[0].Rows[0]["score2"] != null && ds.Tables[0].Rows[0]["score2"].ToString() != "")
                {
                    model.score2 = int.Parse(ds.Tables[0].Rows[0]["score2"].ToString());
                }
                if (ds.Tables[0].Rows[0]["score3"] != null && ds.Tables[0].Rows[0]["score3"].ToString() != "")
                {
                    model.score3 = int.Parse(ds.Tables[0].Rows[0]["score3"].ToString());
                }
                if (ds.Tables[0].Rows[0]["cardcode"] != null && ds.Tables[0].Rows[0]["cardcode"].ToString() != "")
                {
                    model.cardcode = int.Parse(ds.Tables[0].Rows[0]["cardcode"].ToString());
                }
                if (ds.Tables[0].Rows[0]["videcode"] != null && ds.Tables[0].Rows[0]["videcode"].ToString() != "")
                {
                    model.videcode = ds.Tables[0].Rows[0]["videcode"].ToString();
                }
                if (ds.Tables[0].Rows[0]["money"] != null && ds.Tables[0].Rows[0]["money"].ToString() != "")
                {
                    model.money = decimal.Parse(ds.Tables[0].Rows[0]["money"].ToString());
                }
                if (ds.Tables[0].Rows[0]["registerTime"] != null && ds.Tables[0].Rows[0]["registerTime"].ToString() != "")
                {
                    model.registerTime = DateTime.Parse(ds.Tables[0].Rows[0]["registerTime"].ToString());
                }
                return model;
            }
            else
            {
                return null;
            }
        }

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select memberid,memberlogin,memberpwd,membername,sex,birthday,tel1,tel2,phone,email,msn,qq,address,updatetime,logintime,lastime,lastip,flag,state,question,answer,province,city,xinprice,post,rankid,price1,price2,score1,score2,score3,cardcode,videcode,money,registerTime ");
            strSql.Append(" FROM tbMember where isnull(flag,0)!=2 ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" and "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" memberid,memberlogin,memberpwd,membername,sex,birthday,tel1,tel2,phone,email,msn,qq,address,updatetime,logintime,lastime,lastip,flag,state,question,answer,province,city,xinprice,post,rankid,price1,price2,score1,score2,score3,cardcode,videcode,money,registerTime ");
			strSql.Append(" FROM tbMember ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM tbMember ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.memberid desc");
			}
            strSql.Append(")AS Row, T.*  from tbMember T where 1=1 and isnull(flag,0)!=2 ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append( strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@tblName", SqlDbType.VarChar, 255),
					new SqlParameter("@fldName", SqlDbType.VarChar, 255),
					new SqlParameter("@PageSize", SqlDbType.Int),
					new SqlParameter("@PageIndex", SqlDbType.Int),
					new SqlParameter("@IsReCount", SqlDbType.Bit),
					new SqlParameter("@OrderType", SqlDbType.Bit),
					new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
					};
			parameters[0].Value = "tbMember";
			parameters[1].Value = "memberid";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  Method
	}
}


